svyset [pweight=weight] 


*Descriptive Stats
gen female = gender
recode female 1/1 = 0 2/2 = 1 3/3 = 0
sum age educ pid elecparty ideology female psid position yearscuroff yearsanyoff hourswork elecincome eleclandslide runagain termlimits 

*Confirming PID matches party elected as
gen elecrep = elecparty
recode elecrep 1/1 = 0 2/2 = 1
gen elecdem = elecparty
recode elecdem 1/1 = 1 2/2 = 0
tab pid elecrep, col
tab pid elecdem, col


*Showing total N with partisanship of Democrat or Republican
sum elecparty

*Condition variable where 1 = out-party perceptions, 2 = in-party perceptions, 3 = out-party correction, 4 = in-party correction
tab condition1out2in3outc4inc

mlogit condition1out2in3outc4inc age educ pid elecdem ideology female psid position yearscuroff yearsanyoff hourswork elecincome eleclandslide runagain termlimits  if elecparty < 3


*Creating the animosity scale. Perin is perception of the respondent's party (for condition 1, it is the out-party's perception of the respondent's party; for condition 2 it is the in-party's perception of the respondent's party etc.). Perout is perception of the respondent's out-party (for condition 1, it is other party's perception of the respondent's out-party; for condition 2, it is the in-party's perception of the respondent's out-party etc.). For conditions 1 and 3, the relevant perceptions are of one's own party or perin (i.e., outparty perception of in-party). For conditions 2 and 4, the relevant perceptions are of the other party or perout (i.e., in-party perception of out-party). Thus, the created variable perthem gives the preception releavant to the condition.


sum perout perin

gen pertherm  = .
replace pertherm = perin if condition1out2in3outc4inc == 1
replace pertherm = perout if condition1out2in3outc4inc == 2
replace pertherm = perin if condition1out2in3outc4inc == 3
replace pertherm = perout if condition1out2in3outc4inc == 4

*The thermometers were coded so higher scores were more favorable and thus flip them to create animosity and perceieved animosity.
gen animosity = 100-outtherm
gen peranimosity = 100-pertherm
sum animosity peranimosity

*Descriptives of the main outcome measures
sum perout perin peranimosity perpolls percourt perjournal perelect perthreat perharass perviolgoal perviolelec animosity intherm polling courts journalist rejelection threaten harass violgoals violelect if elecparty < 3
 
*Checking alphas and creating undermocratic practice and support for partisan violence scales and perception scales.
alpha perpolls percourt perjournal perelect if elecparty <3
egen perdemnorms = rowmean(perpolls percourt perjournal perelect)
alpha perthreat perharass perviolgoal perviolelec if elecparty <3
egen perviol = rowmean(perthreat perharass perviolgoal perviolelec)
alpha polling courts journalist rejelection if elecparty <3
egen demnorms = rowmean(polling courts journalist rejelection)
alpha threaten harass violgoals violelect if elecparty <3
egen viol = rowmean(threaten harass violgoals violelect)


*Mean scores (Figure 1) For the legislors' scores, we use only conditions 1 and 2 since we do not want to include the correction effect in basic means.
mean animosity if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty <3

mean peranimosity if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3
mean peranimosity if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty <3

mean demnorms if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty <3

mean perdemnorms if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3
mean perdemnorms if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty <3

mean viol if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty <3

mean perviol if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3
mean perviol if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty <3


*The public scores come from Voekel et al.'s (2023) data
ttest animosity = 71.3 if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty <3
ttest peranimosity = 71.3 if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty <3
ttest peranimosity = 71.3 if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3


ttest demnorms = 26.4 if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty <3
ttest perdemnorms = 26.4 if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty <3
ttest perdemnorms = 26.4 if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3


ttest viol = 10.9 if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty <3
ttest  perviol = 10.9 if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty <3
ttest  perviol = 10.9 if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3


*Correlations between legislators' attitudes and perceptions in no correction conditions
pwcorr animosity peranimosity if condition1out2in3outc4inc == 1 & elecparty < 3, sig
pwcorr animosity peranimosity if condition1out2in3outc4inc == 2 & elecparty < 3, sig
pwcorr demnorms perdemnorms if condition1out2in3outc4inc == 1 & elecparty < 3, sig
pwcorr demnorms perdemnorms if condition1out2in3outc4inc == 2 & elecparty < 3, sig
pwcorr viol perviol if condition1out2in3outc4inc == 1 & elecparty < 3, sig
pwcorr viol perviol if condition1out2in3outc4inc == 2 & elecparty < 3, sig

*Mean scores for corrections (Figure 2)
tab condition1out2in3outc4inc, sum(animosity), if elecparty <3
tab condition1out2in3outc4inc, sum(demnorms), if elecparty <3
tab condition1out2in3outc4inc, sum(viol), if elecparty <3


ttest animosity, by(condition1out2in3outc4inc), if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3
ttest demnorms,  by(condition1out2in3outc4inc), if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) & elecparty <3
ttest viol,  by(condition1out2in3outc4inc), if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) & elecparty <3


*Correlations between legislators' attitudes and perceptions in out-party correction conditions
pwcorr animosity peranimosity if condition1out2in3outc4inc == 3 & elecparty < 3, sig
pwcorr demnorms perdemnorms if condition1out2in3outc4inc == 3 & elecparty < 3, sig
pwcorr viol perviol if condition1out2in3outc4inc == 3 & elecparty < 3, sig


*Descriptive stats in SI
tab position if elecparty < 3
tab termlimits if elecparty < 3
tab female if elecparty < 3
tab elecparty if elecparty < 3


*Weighted means in SI
svy: mean animosity if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty <3

svy: mean peranimosity if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3
svy: mean peranimosity if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty <3

svy: mean demnorms if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty <3

svy: mean perdemnorms if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3
svy: mean perdemnorms if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty <3

svy: mean viol if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty <3

svy: mean perviol if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3
svy: mean perviol if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty <3


svy: mean animosity if (condition1out2in3outc4inc == 1) &  elecparty <3
svy: mean animosity if (condition1out2in3outc4inc == 2) &  elecparty <3
svy: mean animosity if (condition1out2in3outc4inc == 3) &  elecparty <3
svy: mean animosity if (condition1out2in3outc4inc == 4) &  elecparty <3

svy: mean demnorms if (condition1out2in3outc4inc == 1) &  elecparty <3
svy: mean demnorms if (condition1out2in3outc4inc == 2) &  elecparty <3
svy: mean demnorms if (condition1out2in3outc4inc == 3) &  elecparty <3
svy: mean demnorms if (condition1out2in3outc4inc == 4) &  elecparty <3


svy: mean viol if (condition1out2in3outc4inc == 1) &  elecparty <3
svy: mean viol if (condition1out2in3outc4inc == 2) &  elecparty <3
svy: mean viol if (condition1out2in3outc4inc == 3) &  elecparty <3
svy: mean viol if (condition1out2in3outc4inc == 4) &  elecparty <3


gen correction = condition1out2in3outc4inc
recode correction 1/2 = 0 3/4 = 1

svy: regress animosity correction if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3

svy: regress demnorms correction if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3

svy: regress viol correction if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty <3


*Weighted correlations in SI (generated from weighted regressions)

svy: regress animosity peranimosity if condition1out2in3outc4inc == 1 & elecparty < 3
svy: regress demnorms perdemnorms if condition1out2in3outc4inc == 1 & elecparty < 3
svy: regress viol perviol if condition1out2in3outc4inc == 1 & elecparty < 3
svy: regress animosity peranimosity if condition1out2in3outc4inc == 2 & elecparty < 3
svy: regress demnorms perdemnorms if condition1out2in3outc4inc == 2 & elecparty < 3
svy: regress viol perviol if condition1out2in3outc4inc == 2 & elecparty < 3
svy: regress animosity peranimosity if condition1out2in3outc4inc == 1 & elecparty < 3
svy: regress demnorms perdemnorms if condition1out2in3outc4inc == 1 & elecparty < 3
svy: regress viol perviol if condition1out2in3outc4inc == 1 & elecparty < 3
svy: regress animosity peranimosity if condition1out2in3outc4inc == 3 & elecparty < 3
svy: regress demnorms perdemnorms if condition1out2in3outc4inc == 3 & elecparty < 3
svy: regress viol perviol if condition1out2in3outc4inc == 3 & elecparty < 3



*Looking at moderatinog effect of size of misperception
gen diffperanimosity = (peranimosity-71.3)
gen conditionoutcorr = condition1out2in3outc4inc
recode conditionoutcorr 0/2 = 0 3/3 = 1 4/4 = 0
gen corrperanim = conditionoutcorr*diffperanimosity
regress animosity diffperanimosity conditionoutcorr corrperanim if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) & elecparty < 3 


gen diffperdemnorms = (perdemnorms-26.4)
gen corrperdemnorms = conditionoutcorr*diffperdemnorms
regress demnorms diffperdemnorms conditionoutcorr corrperdemnorms if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) & elecparty < 3 



*Democrats

*Mean scores 
mean animosity if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty ==1

mean peranimosity if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty ==1
mean peranimosity if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty ==1

mean demnorms if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty ==1

mean perdemnorms if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty ==1
mean perdemnorms if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty ==1

mean viol if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty ==1

mean perviol if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty ==1
mean perviol if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty ==1

*Correlations between legislators' attitudes and perceptions in no correction conditions
pwcorr animosity peranimosity if condition1out2in3outc4inc == 1 & elecparty ==1, sig
pwcorr animosity peranimosity if condition1out2in3outc4inc == 2 & elecparty ==1, sig
pwcorr demnorms perdemnorms if condition1out2in3outc4inc == 1 & elecparty ==1, sig
pwcorr demnorms perdemnorms if condition1out2in3outc4inc == 2 & elecparty ==1, sig
pwcorr viol perviol if condition1out2in3outc4inc == 1 & elecparty ==1, sig
pwcorr viol perviol if condition1out2in3outc4inc == 2 & elecparty ==1, sig

*Mean scores for corrections
tab condition1out2in3outc4inc, sum(animosity), if elecparty ==1
tab condition1out2in3outc4inc, sum(demnorms), if elecparty ==1
tab condition1out2in3outc4inc, sum(viol), if elecparty ==1


ttest animosity, by(condition1out2in3outc4inc), if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty ==1
ttest demnorms,  by(condition1out2in3outc4inc), if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) & elecparty ==1
ttest viol,  by(condition1out2in3outc4inc), if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) & elecparty ==1

*Correlations between legislators' attitudes and perceptions in out-party correction conditions
pwcorr animosity peranimosity if condition1out2in3outc4inc == 3 & elecparty ==1, sig
pwcorr demnorms perdemnorms if condition1out2in3outc4inc == 3 & elecparty ==1, sig
pwcorr viol perviol if condition1out2in3outc4inc == 3 & elecparty ==1, sig







*Republicans

*Mean scores
mean animosity if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty == 2

mean peranimosity if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty ==2
mean peranimosity if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty ==2

mean demnorms if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty ==2

mean perdemnorms if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty ==2
mean perdemnorms if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty ==2

mean viol if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 2) &  elecparty ==2

mean perviol if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty ==2
mean perviol if (condition1out2in3outc4inc == 2 | condition1out2in3outc4inc == 4) &  elecparty ==2

*Correlations between legislators' attitudes and perceptions in no correction conditions
pwcorr animosity peranimosity if condition1out2in3outc4inc == 1 & elecparty ==2, sig
pwcorr animosity peranimosity if condition1out2in3outc4inc == 2 & elecparty ==2, sig
pwcorr demnorms perdemnorms if condition1out2in3outc4inc == 1 & elecparty ==2, sig
pwcorr demnorms perdemnorms if condition1out2in3outc4inc == 2 & elecparty ==2, sig
pwcorr viol perviol if condition1out2in3outc4inc == 1 & elecparty ==2, sig
pwcorr viol perviol if condition1out2in3outc4inc == 2 & elecparty ==2, sig

*Mean scores for corrections
tab condition1out2in3outc4inc, sum(animosity), if elecparty ==2
tab condition1out2in3outc4inc, sum(demnorms), if elecparty ==2
tab condition1out2in3outc4inc, sum(viol), if elecparty ==2


ttest animosity, by(condition1out2in3outc4inc), if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) &  elecparty ==2
ttest demnorms,  by(condition1out2in3outc4inc), if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) & elecparty ==2
ttest viol,  by(condition1out2in3outc4inc), if (condition1out2in3outc4inc == 1 | condition1out2in3outc4inc == 3) & elecparty ==2



*Correlations between legislators' attitudes and perceptions in out-party correction conditions
pwcorr animosity peranimosity if condition1out2in3outc4inc == 3 & elecparty ==2, sig
pwcorr demnorms perdemnorms if condition1out2in3outc4inc == 3 & elecparty ==2, sig
pwcorr viol perviol if condition1out2in3outc4inc == 3 & elecparty ==2, sig





